package queries;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import entitys.Product;

public class GetProductsByMarketingSaleQuery {
/**
 * Execute query
 * @param conn
 * @param marketingSale
 * @return
 */
	public static Object exe(Connection conn, String marketingSale) {
		String s = null;
		ResultSet res = null; 
		Statement stmt;
		
			
			try {
				stmt = conn.createStatement();
				res = stmt.executeQuery("SELECT p.picture,p.id,p.name,p.description,p.price,mp.messageToClient from ccrm.product AS p,ccrm.marketingsales AS ms,marketingpattern AS mp "
						+ "WHERE p.id=mp.productID AND ms.marketingPatternID=mp.patternID AND ms.id='"+marketingSale+"';");
				if(res.next())
				{
					s=String.format("%s #%d \nProduct: %s\nDesription: %s\nPrice: %f\nMessage To Client: %s", res.getString(1), res.getInt(2), res.getString(3), res.getString(4), res.getFloat(5), res.getString(6));
				}
				else
					return null;
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		return s;
		
	}

}
